home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************************
- *
- *
- * MacZoop - "the framework for the rest of us"
- *
- *
- * TextStyleUtils.h - utilties for dealing with styled TextEdit
- *
- *
- * © 1998, Graham Cox
- *
- *
- *
- *************************************************************************************************/
-
-
- #pragma once
-
-
- #ifndef __TEXTSTYLEUTILS__
- #define __TEXTSTYLEUTILS__
-
- #include <TextEdit.h>
-
- enum
- {
- kFaceIsContinuous = 1,
- kFontIsContinuous = 2,
- kSizeIsContinuous = 4
- };
-
- typedef unsigned short FontRunInfo;
-
- #define MAX_SIZES 99
- #define MAX_FONTS 96
-
- // Quickdraw defines plain as being the absence of all other styles, but for flag
- // manipulation, it's handy to set a bit for this, hence:
-
- enum
- {
- kPlainStyle = 0x80
- };
-
- // font run info:
-
- typedef struct
- {
- FontRunInfo fr;
- Style runStyles;
- Style contStyles;
- short numSizes;
- short numFonts;
- unsigned short sizes[MAX_SIZES];
- short fonts[MAX_FONTS];
- }
- TEStyleRunInfo;
-
- // main analysis function:
-
- #if _cplusplus
- extern "C" {
- #endif
-
- void TEGetStyleRunInfo( TEStyleRunInfo* runInfo, TEHandle te );
-
- // utils:
-
- Boolean FontInRun( short aFont, TEStyleRunInfo* runInfo, short* index );
- Boolean SizeInRun( short aSize, TEStyleRunInfo* runInfo, short* index );
-
- #if _cplusplus
- }
- #endif
-
- /*
-
- Sometime you need to know exactly what a run of styles consists of in TextEdit, for example
- when maintaining menus to correctly reflect mixed styles in a run. This function provides one
- element of this functionality by filling in a <TEStyleRunInfo> structure from the current
- selection in a styled TextEdit record. Unlike TEContinuousStyle(), this can report a complete
- list of fonts, styles and sizes in a run, not just whether the run is continuous or not.
-
- The TEStyleRunInfo record:
-
- <fr> is s set of flags indicating which parts of the run are continuous. If any parts are
- continuous, the corresponding fields contain the style, font and size info. For this case,
- the zeroth element of the array fields contains the information, and the others are undefined.
-
- <runStyles> is a bit field following the standard form for styles. If the run is not continuous
- with respect to styles, this indicates the mix of styles- normally you would check the equivalent
- menu items with a dash rather than a checkmark in this case.
-
- <contStyles> is a bitfield indicating if the corresponding style is continuous over the run.
- If 1, the style is continuous, else discontinuous.
-
- <numSizes> for a continuous run of sizes, this is set to 1. For a non-continuous run, this is
- set to the number of array elements actually filled in with size info.
-
- <numFonts> as above, but for the font info.
-
- <sizes> is an array of the different sizes encountered in the run. They are ordered according
- to the order in which they were encountered in the text, not in order of size.
-
- <fonts> is an array of font IDs encountered in the run. The order is run order.
-
-
-
- */
-
-
- #endif